#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Math;
using Weazel.Gezel.Simulator.Reference.Profiling;

#endregion

namespace Weazel.Gezel.Simulator.Reference
{
    class IpOutputSignal : AbstractSignal
    {
        private Profiler profiler;
        private AbstractIpBlock owner;
        private uint width;
        private bool signed;

        public IpOutputSignal(Symid id, uint width, bool signed, AbstractIpBlock owner, Simulation sim)
            : base(id, null)
        {
            this.width = width;
            this.signed = signed;
            this.owner = owner;

            if (sim.profiler != null)
            {
                profiler = sim.profiler;
                profiler.MakeOperation(this, Width());
            }
        }

        internal override Integer Evaluate(AbstractIpBlock ip, long g)
        {
            owner.Evaluate(g, false);
            generation = g;

            Integer outValue = owner.outValue(this);

            if (profiler != null)
                profiler.EvaluateOperation(Id, outValue);

            return outValue;
        }

        Integer peekval()
        {
            return owner.outValue(this);
        }

        internal override uint Width()
        {
            return width;
        }

        internal override uint Signed()
        {
            return signed? (uint)1 : (uint)0;
        }

        public override bool TraceToSignal(Symid toSignalId, List<AbstractSignal> signals)
        {
            return false;
        }
    }
}
